import { defineStore } from 'pinia'
import { reactive } from 'vue'

//选中的文章
export const Article = reactive({
  Id: 0,
  category: '',
})


// 创建一个store，用于管理登录用户信息
export const useUser = defineStore('user', {
  // 定义状态
  state: () => {
    return {
      // 是否显示登录界面
      showLogin: false,
      // 用户信息
      user: {
        userId: '',
        userName: '',
        userPhoneNumber: '',
        avatar: ''
      }
    }
  },
  actions: {
    // 修改登录界面的状态
    setShowLogin(val) {
      this.showLogin = val
    },
    // 设置用户信息
    setUser(val) {
      this.user = val
    },

    // 重置方法
    reset() {
      this.user = {
        userId: '',
        userName: '',
        userPhoneNumber: ''
      }
    }
  }
})

export const editedArticle = defineStore('article', {
  state: () => {
    return {
      // 文章信息
      article: {
        id: '',
        typeId: '',
        title: '',
        contentType: '',
        markdownContent: '',
        htmlContent: '',
        tagIds: '',
        headImg: '',
        category: '',
      }
    }
  },
  actions: {
    //设置文章信息
    setArticle(val) {
      this.article = val
    },
    // 重置方法
    reset() {
      this.article = {
        id: '',
        typeId: '',
        title: '',
        contentType: "MARKDOWN",
        markdownContent: '',
        htmlContent: '',
        tags: '',
        headImg: '',
        category: '',
      }
    }
  }
})

